﻿using AppsFlyerSDK;
using Facebook.Unity;
using System.Collections.Generic;
using UnityEngine;

namespace PickMeUp
{
    public class GameInitializeState : BaseGameState
    {
        public override GameDefines.E_GameFSMState Id => GameDefines.E_GameFSMState.InitializeState;

        public GameInitializeState(GameApp owner) : base(owner)
        {
            //GlobalLoadingPanel.Instance.InitGlobalLoadingPanel();
            UnityEngine.Object.Instantiate(Resources.Load<AppsFlyerObjectScript>("Prefabs/SDK/AppsFlyerObject"), Owner.transform);
            // 初始化Facebook
            FB.Init(() =>
            {
                FB.ActivateApp();
                string logMessage = string.Format("OnInitCompleteCalled IsLoggedIn='{0}' IsInitialized='{1}'", FB.IsLoggedIn, FB.IsInitialized);
                AppsFlyer.AFLog("face book init", logMessage);
            });

        }

        public override void OnEnterState()
        {
            base.OnEnterState();
            Application.targetFrameRate = GameApp.GameTargetFrame;
        }

        public override bool TransitionState(float deltaTime, out GameDefines.E_GameFSMState id)
        {
            id = GameDefines.E_GameFSMState.LaunchState;
            return GetFBIsReady();
        }

        private bool GetFBIsReady() => FB.IsInitialized;
    }
}